home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / snpd9611.zip / FTIME.C < prev    next >
C/C++ Source or Header  |  1996-11-24  |  2KB  |  86 lines

  1. .I 0 2
  2. /* +++Date last modified: 24-Aug-1996 */
  3.  
  4. .I 4 3
  5. #include <time.h>
  6. #include "ftime.h"
  7.  
  8. .D 7 2
  9. .I 12 1
  10.  typedef unsigned FTIME_T_;
  11. .I 63 74
  12.  
  13. static void _ftimecnvrt(struct ftime *ft, struct tm *time, time_t *tt)
  14. {
  15.       time->tm_sec  = ft->ft_tsec * 2;
  16.       time->tm_min  = ft->ft_min;
  17.       time->tm_hour = ft->ft_hour;
  18.       time->tm_mday = ft->ft_day;
  19.       time->tm_mon  = ft->ft_month - 1;
  20.       time->tm_year = ft->ft_year + 80;
  21.       *tt = mktime(time);                 /* Fill in rest of the struct */
  22. }
  23.  
  24. void ftime2tm(struct ftime *ft, struct tm *time)
  25. {
  26.       time_t tt;
  27.       
  28.       _ftimecnvrt(ft, time, &tt);
  29. }
  30.  
  31. time_t ftime2time(struct ftime *ft)
  32. {
  33.       struct tm time;
  34.       time_t tt;
  35.       
  36.       _ftimecnvrt(ft, &time, &tt);
  37.       return tt;
  38. }
  39.  
  40. #ifdef TEST
  41.  
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include "unistd.h"
  45. #include "errors.h"
  46. #include "sniptype.h"
  47.  
  48. #ifdef __WATCOMC__
  49.  #pragma off (unreferenced);
  50. #endif
  51. #ifdef __TURBOC__
  52.  #pragma argsused
  53. #endif
  54.  
  55. main(int argc, char *argv[])
  56. {
  57.       struct ftime ft;
  58.       struct tm time;
  59.       FILE *fp;
  60.       char timeline[80];
  61.  
  62.       fp = cant(argv[0], "r");
  63.       if (Success_ != getftime(fileno(fp), &ft))
  64.             ErrExit("getftime() failed");
  65.       ftime2tm(&ft, &time);
  66.       printf("ft_tsec = %d\n", ft.ft_tsec);
  67.       printf("ft_min  = %d\n", ft.ft_min);
  68.       printf("ft_hour = %d\n", ft.ft_hour);
  69.       printf("ft_day  = %d\n", ft.ft_day);
  70.       printf("ft_month= %d\n", ft.ft_month);
  71.       printf("ft_year = %d\n", ft.ft_year);
  72.       puts("");
  73.       printf("tm_sec  = %d\n", time.tm_sec);
  74.       printf("tm_min  = %d\n", time.tm_min);
  75.       printf("tm_hour = %d\n", time.tm_hour);
  76.       printf("tm_mday = %d\n", time.tm_mday);
  77.       printf("tm_mon  = %d\n", time.tm_mon);
  78.       printf("tm_year = %d\n", time.tm_year);
  79.  
  80.       strftime(timeline, 80, "\n%c\n", &time);
  81.       puts(timeline);
  82.       return EXIT_SUCCESS;
  83. }
  84.  
  85. #endif /* TEST */
  86.